package  
{
	import org.flixel.FlxGroup;
	import org.flixel.FlxSprite;
	import org.flixel.FlxG;
	
	/**
	 * ...
	 * @author João Brant
	 * @author Lucas Mattos
	 */
	public class Casas extends FlxGroup
	{
		public var x:int;
		public var y:int;
				
		[Embed(source = "../assets/envy/casa1.png")]
		public static var casa1:Class;
		
		public function Casas() 
		{
			super();
			
		}
		public override function update():void
		{			
			var newParte:ParteRua;
			var anotherParte:ParteRua;
						
			if (this.members.length == 0)
			{
				//RuaMeioFio
				newParte = createCasa(x, y);
			}
			
			this.sort("x", FlxGroup.DESCENDING);
			
						
			while (members[0].x + members[0].width < Main.windowWidth+FlxG.camera.scroll.x)
			{
				//trace(" " + (x + members[0].x + members[0].width));
				//RuaMeioFio
				newParte = createCasa(x + members[0].x + members[0].width, y);
				
				this.sort("x", FlxGroup.DESCENDING);
			}			
		}
		
		private function createCasa(posx:int, posy:int):ParteRua
		{
			var newParte:ParteRua;
			
			var rand:int = Math.random()*10;
			
			switch(rand)
			{
				case 0:
					newParte = new ParteRua(casa1); break;
				default:
					newParte = new ParteRua(casa1); break;
			}
					
			newParte.x = posx;
			newParte.y = posy - Math.random()*100;
			add(newParte);
			
			return newParte;
		}
	}
	

}